package day17.edu;

import org.junit.Test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

// Created: 17/09/2025, ChangJiang Ru
public class DateTest {
    @Test
    public void test1()
    {
        long time = System.currentTimeMillis();
        System.out.println(time);

        System.out.println("======");
        Date date1 = new Date();
        System.out.println(date1);
        System.out.println(date1.toString());

        long milliseconds = date1.getTime();
        System.out.println(milliseconds);

        Date date2 = new Date(11112341534242L);
        System.out.println(date2);
    }
    
    @Test
    public void test2()
    {
        java.sql.Date date1 = new java.sql.Date(11111234532114L);
        System.out.println(date1);

        System.out.println(date1.getTime());
    }
    
    @Test
    public void test3 () throws ParseException
    {
        SimpleDateFormat sdf = new SimpleDateFormat();
        Date date1 = new Date();
        String strDate = sdf.format(date1);
        System.out.println(strDate);

        System.out.println("=======");
        Date date2 = sdf.parse("2025/9/17 16:36");
        System.out.println(date2.toString());
    }
    
    @Test
    public void test4()
    {
        Calendar calendar = Calendar.getInstance();
        System.out.println(calendar.getClass());

        System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
        System.out.println(calendar.get(Calendar.DAY_OF_WEEK));

        calendar.set(Calendar.DAY_OF_MONTH, 23);
        System.out.println(calendar.get(Calendar.DAY_OF_MONTH));

        calendar.add(Calendar.DAY_OF_MONTH, 3);
        System.out.println(calendar.get(Calendar.DAY_OF_MONTH));

        calendar.add(Calendar.DAY_OF_MONTH, -5);
        System.out.println(calendar.get(Calendar.DAY_OF_MONTH));

        Date date = calendar.getTime();
        System.out.println(date);

        Date date1 = new Date();
        calendar.setTime(date1);
        System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
    }
    
    @Test
    public void test5()
    {
        Date date1 = new Date();
        java.sql.Date date2 = new java.sql.Date(date1.getTime());
        System.out.println(date2);
    }
    
    @Test
    public void test6() throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String pattern = "2022-12-13";

        Date date1 = sdf.parse(pattern);

        java.sql.Date date2 = new java.sql.Date(date1.getTime());
        System.out.println(date2);
    }

    @Test
    public void test7()
    {
        String s1 = "hello";
        String s2 = s1.replace('l', 'w');
        System.out.println(s1);
        System.out.println(s2);

        System.out.println("======");
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.DAY_OF_MONTH, 23);
        System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
    }


}
